package com.christianposta.learnddd.domain.model.location;

import org.apache.commons.lang.Validate;


import com.christianposta.learnddd.domain.shared.Entity;

public class Location implements Entity<Location> {

	private UnLocode unLocode;
	private String name;
	
	/*
	 * Special location that marks an unknown or null location
	 */
	public static final Location UNKNOWN = new Location(new UnLocode("XXXXX"), "Unknown Location");
	
	public Location(final UnLocode unLocode, final String name){
		Validate.notNull(unLocode);
		Validate.notNull(name);
		
		this.unLocode = unLocode;
		this.name = name;
	}
	
	public UnLocode unLocode(){
		return this.unLocode;
	}
	
	public String name(){
		return this.name;
	}

	public boolean sameIdentityAs(Location other) {
		return other != null && this.unLocode.sameValueAs(other.unLocode);
	}

	@Override
	public int hashCode() {
	    return unLocode.hashCode();
	}

	@Override
	public boolean equals(Object object) {
	    if (object == null) {
	        return false;
	      }
	      if (this == object) {
	        return true;
	      }
	      if (!(object instanceof Location)) {
	        return false;
	      }
	      Location other = (Location) object;
	      return sameIdentityAs(other);
	}
	
	// needed by Hibernate
	Location() {
		
	}
	private Long id;

}
